# include <stdio.h>
# include <graphics.h>
# include <math.h>
# include <stdlib.h>
# include <string.h>
# include <time.h>
#include "DrawScrew.h"

double bottenangle = 0;
double bottenangle2 = 0;
double triangles = 90;
double compass_is_down = 0;
int compass_mouse_x = 0;
int compass_mouse_y = 0;
int compass_mouse_x_cur = 0;
int compass_mouse_y_cur = 0;
double compass_temp_data = 0;
extern double compass_angle_original_data;
extern double rotationangle;//整个表盘旋转
double pointrotationangle = 0;
double compass_temp_data1 = 0;
double datarotationangle = 0;//表示旋钮控制左上角显示屏上数字的增加值
double realrotationangle = 0;

extern int G_light;

//画出表盘下方两个旋钮
void draw_downbotten(double realrotationangle, int compass_x, int compass_y, int compass_r) {
	//左侧旋钮
	setfillcolor(BLACK);
	for (int i = 0; i < 100; i++) {
		ege_fillellipse(compass_x - compass_r * (1.45 + i * 0.001), compass_y + compass_r * (1.1 + i * 0.001), compass_r * 0.45, compass_r * 0.45);
	}
	setfillcolor(EGEARGB(0xff, 0x1b, 0x20, 0x25));
	ege_fillellipse(compass_x - compass_r * 1.545, compass_y + compass_r * 1.205, compass_r * 0.44, compass_r * 0.44);

	ege_enable_aa(false);
	ege_point graphics[7];

	graphics[0].x = -0.095 * compass_r * cos(bottenangle * PI / 180) - 0.175 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22;
	graphics[0].y = 0.175 * compass_r * cos(bottenangle * PI / 180) - 0.095 * compass_r * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22;

	graphics[1].x = -0.035 * compass_r * cos(bottenangle * PI / 180) - 0.125 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22;
	graphics[1].y = 0.125 * compass_r * cos(bottenangle * PI / 180) - 0.035 * compass_r * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22;

	graphics[2].x = -0.035 * compass_r * cos(bottenangle * PI / 180) - 0.125 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22;
	graphics[2].y = 0.125 * compass_r * cos(bottenangle * PI / 180) - 0.035 * compass_r * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22;

	graphics[3].x = 0.122 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22;
	graphics[3].y = -0.122 * compass_r * cos(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22;

	graphics[4].x = 0.035 * compass_r * cos(bottenangle * PI / 180) - 0.125 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22;
	graphics[4].y = 0.125 * compass_r * cos(bottenangle * PI / 180) + 0.035 * compass_r * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22;

	graphics[5].x = 0.035 * compass_r * cos(bottenangle * PI / 180) - 0.125 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22;
	graphics[5].y = 0.125 * compass_r * cos(bottenangle * PI / 180) + 0.035 * compass_r * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22;

	graphics[6].x = 0.095 * compass_r * cos(bottenangle * PI / 180) - 0.175 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22;
	graphics[6].y = 0.175 * compass_r * cos(bottenangle * PI / 180) + 0.095 * compass_r * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22;

	setlinewidth(compass_r * 0.01);
	line((-0.095 * compass_r - 1) * cos(bottenangle * PI / 180) - 0.175 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22, 0.175 * compass_r * cos(bottenangle * PI / 180) - 0.095 * compass_r * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22, (0.095 * compass_r + 1) * cos(bottenangle * PI / 180) - 0.175 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22, 0.175 * compass_r * cos(bottenangle * PI / 180) + 0.095 * compass_r * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22);
	setlinewidth(compass_r * 0.02);
	ege_bezier(7, graphics);
	setfillcolor(WHITE);
	floodfill(compass_x - compass_r * 1.325, compass_y + compass_r * 1.425, WHITE);

	ege_enable_aa(true);
	graphics[0].x = (-0.095 * compass_r - 1) * cos(bottenangle * PI / 180) - 0.175 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22;
	graphics[0].y = 0.175 * compass_r * cos(bottenangle * PI / 180) - (0.095 * compass_r - 1) * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22;

	graphics[1].x = (-0.035 * compass_r - 1) * cos(bottenangle * PI / 180) - 0.125 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22;
	graphics[1].y = 0.125 * compass_r * cos(bottenangle * PI / 180) - (0.035 * compass_r - 1) * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22;

	graphics[2].x = (-0.035 * compass_r - 1) * cos(bottenangle * PI / 180) - 0.125 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22;
	graphics[2].y = 0.125 * compass_r * cos(bottenangle * PI / 180) - (0.035 * compass_r - 1) * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22;

	graphics[3].x = 0.125 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22;
	graphics[3].y = -0.125 * compass_r * cos(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22;

	graphics[4].x = (0.035 * compass_r + 1) * cos(bottenangle * PI / 180) - 0.125 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22;
	graphics[4].y = 0.125 * compass_r * cos(bottenangle * PI / 180) + (0.035 * compass_r + 1) * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22;

	graphics[5].x = (0.035 * compass_r + 1) * cos(bottenangle * PI / 180) - 0.125 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22;
	graphics[5].y = 0.125 * compass_r * cos(bottenangle * PI / 180) + (0.035 * compass_r + 1) * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22;

	graphics[6].x = (0.095 * compass_r + 1) * cos(bottenangle * PI / 180) - 0.175 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22;
	graphics[6].y = 0.175 * compass_r * cos(bottenangle * PI / 180) + (0.095 * compass_r + 1) * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22;

	setlinewidth(compass_r * 0.02);
	line((-0.095 * compass_r - 2) * cos(bottenangle * PI / 180) - 0.175 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22, 0.175 * compass_r * cos(bottenangle * PI / 180) - 0.095 * compass_r * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22, (0.095 * compass_r + 1) * cos(bottenangle * PI / 180) - 0.175 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.545 + compass_r * 0.22, 0.175 * compass_r * cos(bottenangle * PI / 180) + 0.095 * compass_r * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.205 + compass_r * 0.22);
	setlinewidth(compass_r * 0.03);
	ege_bezier(7, graphics);

	LOGFONTW font;
	setfont(compass_r * 0.1, compass_r * 0.1, "Leelawadee", -bottenangle * 10, 0, 0, 0, 0, 0);
	settextjustify(CENTER_TEXT, CENTER_TEXT);
	char stringBuffer[64];
	strcpy_s(stringBuffer, "COURSE");
	getfont(&font);
	setfillcolor(EGEARGB(0xff, 0x1b, 0x20, 0x25));
	ege_point textbackground[4];
	textbackground[0].x = -0.18 * compass_r * cos(bottenangle * PI / 180) + 0.05 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.325;
	textbackground[0].y = -0.05 * compass_r * cos(bottenangle * PI / 180) - 0.18 * compass_r * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.425;

	textbackground[1].x = 0.18 * compass_r * cos(bottenangle * PI / 180) + 0.05 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.325;
	textbackground[1].y = -0.05 * compass_r * cos(bottenangle * PI / 180) + 0.18 * compass_r * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.425;

	textbackground[2].x = 0.18 * compass_r * cos(bottenangle * PI / 180) - 0.04 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.325;
	textbackground[2].y = 0.04 * compass_r * cos(bottenangle * PI / 180) + 0.18 * compass_r * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.425;

	textbackground[3].x = -0.18 * compass_r * cos(bottenangle * PI / 180) - 0.04 * compass_r * sin(bottenangle * PI / 180) + compass_x - compass_r * 1.325;
	textbackground[3].y = 0.04 * compass_r * cos(bottenangle * PI / 180) - 0.18 * compass_r * sin(bottenangle * PI / 180) + compass_y + compass_r * 1.425;

	ege_fillpoly(4, textbackground);
	ege_drawtext(stringBuffer, compass_x - compass_r * 1.325, compass_y + compass_r * 1.425);


	//右侧旋钮
	setfillcolor(BLACK);
	for (int i = 0; i < 100; i++) {
		ege_fillellipse(compass_x + compass_r * (1.05 - i * 0.001), compass_y + compass_r * (1.1 + i * 0.001), compass_r * 0.45, compass_r * 0.45);
	}
	setfillcolor(EGEARGB(0xff, 0x1b, 0x20, 0x25));
	ege_fillellipse(compass_x + compass_r * 0.955, compass_y + compass_r * 1.205, compass_r * 0.44, compass_r * 0.44);

	setlinewidth(compass_r * 0.02);
	setcolor(EGEARGB(0xff, 0xC7, 0x66, 0x4D));
	ege_point triangle[4];
	triangle[0].x = 0.18 * compass_r * sin(bottenangle2 * PI / 180) + compass_x + compass_r * 1.175;
	triangle[0].y = (-0.18 * compass_r) * cos(bottenangle2 * PI / 180) + compass_y + compass_r * 1.425;

	triangle[1].x = (-0.7 * compass_r * 0.22) * cos(bottenangle2 * PI / 180) - 0.11 * compass_r * sin(bottenangle2 * PI / 180) + compass_x + compass_r * 1.175;
	triangle[1].y = 0.11 * compass_r * cos(bottenangle2 * PI / 180) - 0.7 * compass_r * 0.22 * sin(bottenangle2 * PI / 180) + compass_y + compass_r * 1.425;

	triangle[2].x = (0.7 * compass_r * 0.22) * cos(bottenangle2 * PI / 180) - 0.11 * compass_r * sin(bottenangle2 * PI / 180) + compass_x + compass_r * 1.175;
	triangle[2].y = 0.11 * compass_r * cos(bottenangle2 * PI / 180) + 0.7 * compass_r * 0.22 * sin(bottenangle2 * PI / 180) + compass_y + compass_r * 1.425;

	triangle[3].x = 0.18 * compass_r * sin(bottenangle2 * PI / 180) + compass_x + compass_r * 1.175;
	triangle[3].y = (-0.18 * compass_r) * cos(bottenangle2 * PI / 180) + compass_y + compass_r * 1.425;
	ege_drawpoly(4, triangle);

	LOGFONTW font2;
	setfont(compass_r * 0.125, compass_r * 0.1, "Leelawadee", -bottenangle2 * 10, 0, 1000, 0, 0, 0);
	settextjustify(CENTER_TEXT, CENTER_TEXT);
	strcpy_s(stringBuffer, "HDG");
	getfont(&font);
	setfillcolor(EGEARGB(0xff, 0x1b, 0x20, 0x25));
	textbackground[0].x = -0.18 * compass_r * cos(bottenangle2 * PI / 180) + 0.05 * compass_r * sin(bottenangle2 * PI / 180) + compass_x + compass_r * 1.175;
	textbackground[0].y = -0.05 * compass_r * cos(bottenangle2 * PI / 180) - 0.18 * compass_r * sin(bottenangle2 * PI / 180) + compass_y + compass_r * 1.425;

	textbackground[1].x = 0.18 * compass_r * cos(bottenangle2 * PI / 180) + 0.05 * compass_r * sin(bottenangle2 * PI / 180) + compass_x + compass_r * 1.175;
	textbackground[1].y = -0.05 * compass_r * cos(bottenangle2 * PI / 180) + 0.18 * compass_r * sin(bottenangle2 * PI / 180) + compass_y + compass_r * 1.425;

	textbackground[2].x = 0.18 * compass_r * cos(bottenangle2 * PI / 180) - 0.04 * compass_r * sin(bottenangle2 * PI / 180) + compass_x + compass_r * 1.175;
	textbackground[2].y = 0.04 * compass_r * cos(bottenangle2 * PI / 180) + 0.18 * compass_r * sin(bottenangle2 * PI / 180) + compass_y + compass_r * 1.425;

	textbackground[3].x = -0.18 * compass_r * cos(bottenangle2 * PI / 180) - 0.04 * compass_r * sin(bottenangle2 * PI / 180) + compass_x + compass_r * 1.175;
	textbackground[3].y = 0.04 * compass_r * cos(bottenangle2 * PI / 180) - 0.18 * compass_r * sin(bottenangle2 * PI / 180) + compass_y + compass_r * 1.425;
	ege_fillpoly(4, textbackground);
	ege_drawtext(stringBuffer, compass_x + compass_r * 1.175, compass_y + compass_r * 1.425);

	//表盘上的指针，与右侧按钮有关
	setcolor(EGEARGB(0xff, 0xC7, 0x66, 0x4D));
	ege_point triangle2[5];
	triangle2[0].x = -compass_r * sin((triangles + realrotationangle) * PI / 180) + compass_x;
	triangle2[0].y = compass_r * cos((triangles + realrotationangle) * PI / 180) + compass_y;

	triangle2[1].x = -0.95 * compass_r * sin((triangles + realrotationangle) * PI / 180) + compass_x;
	triangle2[1].y = compass_r * 0.95 * cos((triangles + realrotationangle) * PI / 180) + compass_y;

	triangle2[2].x = -0.05 * compass_r * cos((triangles + realrotationangle) * PI / 180) - 0.85 * compass_r * sin((triangles + realrotationangle) * PI / 180) + compass_x;
	triangle2[2].y = 0.85 * compass_r * cos((triangles + realrotationangle) * PI / 180) - 0.05 * compass_r * sin((triangles + realrotationangle) * PI / 180) + compass_y;

	triangle2[3].x = 0.05 * compass_r * cos((triangles + realrotationangle) * PI / 180) - 0.85 * compass_r * sin((triangles + realrotationangle) * PI / 180) + compass_x;
	triangle2[3].y = 0.85 * compass_r * cos((triangles + realrotationangle) * PI / 180) + 0.05 * compass_r * sin((triangles + realrotationangle) * PI / 180) + compass_y;

	triangle2[4].x = -0.95 * compass_r * sin((triangles + realrotationangle) * PI / 180) + compass_x;
	triangle2[4].y = compass_r * 0.95 * cos((triangles + realrotationangle) * PI / 180) + compass_y;
	ege_drawpoly(5, triangle2);

	setcolor(WHITE);
	setlinewidth(compass_r * 0.01);
	mousepos(&compass_mouse_x, &compass_mouse_y);
	if (compass_mouse_x >= compass_x - compass_r * 1.545 && compass_mouse_x <= compass_x - compass_r * 1.105 && compass_mouse_y >= compass_y + compass_r * 1.205 && compass_mouse_y <= compass_y + compass_r * 1.645) {
		ege_ellipse(compass_x - compass_r * 1.545, compass_y + compass_r * 1.205, compass_r * 0.44, compass_r * 0.44);
	}

	//鼠标调控左侧旋钮
	if (GetAsyncKeyState(0x02) & 0x8000) {
		if (compass_is_down == 0) {
			compass_is_down = 1;
			mousepos(&compass_mouse_x, &compass_mouse_y);
			compass_mouse_x_cur = compass_mouse_x;
			compass_mouse_y_cur = compass_mouse_y;
		}
		if (compass_is_down == 1) {
			if (compass_mouse_x_cur >= compass_x - compass_r * 1.545 && compass_mouse_x_cur <= compass_x - compass_r * 1.105 && compass_mouse_y_cur >= compass_y + compass_r * 1.205 && compass_mouse_y_cur <= compass_y + compass_r * 1.645) {
				mousepos(&compass_mouse_x, &compass_mouse_y);
				if (compass_mouse_y > compass_mouse_y_cur) {
					bottenangle -= (compass_mouse_y - compass_mouse_y_cur) / 30;
					if (datarotationangle < 360) {
						datarotationangle -= 0.1;
					}
					else {
						datarotationangle = 0;
					}
					//data的处理
					compass_temp_data1 = compass_angle_original_data;
					while (compass_temp_data1 < 0) {
						compass_temp_data1 += 360;
					}
					while (compass_temp_data1 > 360) {
						compass_temp_data1 -= 360;
					}
					//更新数据
					compass_angle_original_data -= 0.1;
				}
				else {
					bottenangle -= (compass_mouse_y - compass_mouse_y_cur) / 30;
					if (datarotationangle < 360) {
						datarotationangle += 0.1;
					}
					else {
						datarotationangle = 0;
					}
					//data的处理
					compass_temp_data1 = compass_angle_original_data;
					while (compass_temp_data1 < 0) {
						compass_temp_data1 += 360;
					}
					while (compass_temp_data1 > 360) {
						compass_temp_data1 -= 360;
					}
					//更新数据
					compass_angle_original_data += 0.1;
				}
			}
		}

	}
	else if (compass_is_down == 1) {
		compass_is_down = 0;
	}

	setcolor(WHITE);
	setlinewidth(compass_r * 0.01);
	mousepos(&compass_mouse_x, &compass_mouse_y);
	if (compass_mouse_x >= compass_x + compass_r * 0.955 && compass_mouse_x <= compass_x + compass_r * 1.395 && compass_mouse_y >= compass_y + compass_r * 1.205 && compass_mouse_y <= compass_y + compass_r * 1.645) {
		ege_ellipse(compass_x + compass_r * 0.955, compass_y + compass_r * 1.205, compass_r * 0.44, compass_r * 0.44);
	}

	//鼠标调控右侧旋钮
	if (GetAsyncKeyState(0x02) & 0x8000) {
		if (compass_is_down == 0) {
			compass_is_down = 1;
			mousepos(&compass_mouse_x, &compass_mouse_y);
			compass_mouse_x_cur = compass_mouse_x;
			compass_mouse_y_cur = compass_mouse_y;
		}
		if (compass_is_down == 1) {
			if (compass_mouse_x_cur >= compass_x + compass_r * 0.955 && compass_mouse_x_cur <= compass_x + compass_r * 1.395 && compass_mouse_y_cur >= compass_y + compass_r * 1.205 && compass_mouse_y_cur <= compass_y + compass_r * 1.645) {
				ege_ellipse(compass_x + compass_r * 0.955, compass_y + compass_r * 1.205, compass_r * 0.44, compass_r * 0.44);
				mousepos(&compass_mouse_x, &compass_mouse_y);
				if (compass_mouse_y > compass_mouse_y_cur) {
					bottenangle2 -= (compass_mouse_y - compass_mouse_y_cur) / 70;
					triangles -= (compass_mouse_y - compass_mouse_y_cur) / 70;
				}
				else {
					bottenangle2 -= (compass_mouse_y - compass_mouse_y_cur) / 70;
					triangles -= (compass_mouse_y - compass_mouse_y_cur) / 70;
				}
			}
		}

	}
	else if (compass_is_down == 1) {
		compass_is_down = 0;
	}
}

void draw1(int compass_x, int compass_y, int compass_r) {
	setcolor(WHITE);
	char num[12] = { '9','0','1','2','3','4','5','6','7','8','9','0' };
	double useful1 = fmod(compass_temp_data + datarotationangle, 10);//得到的是千位及其以下的数字
	double useful01 = fmod(compass_temp_data + datarotationangle, 1);//得到的是百位及其以下的数字
	setfillcolor(WHITE);
	int num1 = useful1 / 1;//准确的千位位数;
	int num2 = num1 - 1;//千位数 - 1；
	int num3 = num1 + 1;//千位数 + 1；
	//用于存储暂时有使用需求的数字
	char nums[3] = {};
	//将有用的字符存入；
	nums[0] = num[num2 + 1];
	nums[1] = num[num1 + 1];
	nums[2] = num[num3 + 1];


	//计算精细化坐标（加入十位和个位数字进行处理）
	double y_100 = useful01 / 1 * compass_r * 0.2 + compass_y - compass_r * 1.2;
	//设定字体
	setfont(compass_r * 0.2, compass_r * 0.1, "Leelawadee");//设定字体
	for (int i = 0; i < 3; i++) {
		outtextxy(compass_x - compass_r * 1.22 + compass_r * 0.2 * 2, y_100 - compass_r * 0.2 * (i - 1), nums[i]);
	}
}
void draw10(int compass_x, int compass_y, int compass_r) {
	setcolor(WHITE);
	char num[12] = { '9','0','1','2','3','4','5','6','7','8','9','0' };
	double useful10 = fmod(compass_temp_data + datarotationangle, 100);//得到的是百位及其以下的数字
	double useful1 = fmod(compass_temp_data + datarotationangle, 10);//得到的是十位及其以下的数字
	setfillcolor(WHITE);
	int num1 = useful10 / 10;//准确的百位数;
	int num2 = num1 - 1;//千位数 - 1；
	int num3 = num1 + 1;//千位数 + 1；
	//用于存储暂时有使用需求的数字
	char nums[3] = {};
	//将有用的字符存入；
	nums[0] = num[num2 + 1];
	nums[1] = num[num1 + 1];
	nums[2] = num[num3 + 1];
	if (compass_temp_data >= 359) {
		nums[2] = '0';
	}

	//计算精细化坐标（加入十位和个位数字进行处理）
	double y_100 = (useful1 - 9) / 1 * compass_r * 0.2 + compass_y - compass_r * 1.2;
	//设定字体
	setfont(compass_r * 0.2, compass_r * 0.1, "Leelawadee");//设定字体
	for (int i = 0; i < 3; i++) {
		if (useful1 > 9) {
			outtextxy(compass_x - compass_r * 1.17 + compass_r * 0.2, y_100 + compass_r * 0.2 * -(i - 1), nums[i]);
		}
		else {
			outtextxy(compass_x - compass_r * 1.17 + compass_r * 0.2, compass_y - compass_r * 1.2 + compass_r * 0.2 * -(i - 1), nums[i]);
		}
	}
}
void draw100(int compass_x, int compass_y, int compass_r) {
	setcolor(WHITE);
	char num[5] = { '3','0','1','2','3' };
	double useful100 = fmod(compass_temp_data + datarotationangle, 1000);//得到的是百位及其以下的数字
	double useful10 = fmod(compass_temp_data + datarotationangle, 100);//得到的是十位及其以下的数字
	setfillcolor(WHITE);
	int num1 = useful100 / 100;//准确的百位数;
	int num2 = num1 - 1;//百位数 - 1；
	int num3 = num1 + 1;//百位数 + 1；
	//用于存储暂时有使用需求的数字
	char nums[3] = {};
	//将有用的字符存入；
	nums[0] = num[num2 + 1];
	nums[1] = num[num1 + 1];
	nums[2] = num[num3 + 1];
	if (compass_temp_data >= 359) {
		nums[2] = '0';
	}
	//计算精细化坐标（加入十位和个位数字进行处理）double y_100 = -(useful1 - 9) / 1 * compass_r * 0.25 + compass_y;
	double y_100 = (useful10 - 99) / 1 * compass_r * 0.2 + compass_y - compass_r * 1.2;
	//设定字体
	setfont(compass_r * 0.2, compass_r * 0.1, "Leelawadee");//设定字体
	for (int i = 0; i < 3; i++) {
		if (useful10 > 99) {
			outtextxy(compass_x - compass_r * 1.12, y_100 + compass_r * 0.2 * -(i - 1), nums[i]);
		}
		else {
			outtextxy(compass_x - compass_r * 1.12, compass_y - compass_r * 1.2 + compass_r * 0.2 * -(i - 1), nums[i]);
		}
	}
}

//遮盖函数
void cover(int compass_x, int compass_y, int compass_r) {
	setfillcolor(EGEARGB(0xff, 0x1b, 0x20, 0x25));
	ege_fillrect(compass_x - compass_r * 1.2, compass_y - compass_r * 1.075, compass_r * 0.45, compass_r * 0.4);
	setfillcolor(EGEARGB(0xff, 0x24, 0x28, 0x33));
	ege_fillrect(compass_x - compass_r * 1.2, compass_y - compass_r * 1.5, compass_r * 0.45, compass_r * 0.1);
	setfillcolor(EGEARGB(0xff, 0x1b, 0x20, 0x25));
	ege_fillrect(compass_x - compass_r * 1.2, compass_y - compass_r * 1.4, compass_r * 0.45, compass_r * 0.1);
}

//画出表盘两侧的数字显示屏
void draw_sidesscreen(int compass_x, int compass_y, int compass_r)
{
	//左侧显示屏外框
	setcolor(EGEARGB(0xff, 0x24, 0x28, 0x33));
	ege_rectangle(compass_x - compass_r * 1.2, compass_y - compass_r * 1.3, compass_r * 0.45, compass_r * 0.22);
	ege_line(compass_x - compass_r * 1.05, compass_y - compass_r * 1.3, compass_x - compass_r * 1.05, compass_y - compass_r * 1.08);
	ege_line(compass_x - compass_r * 0.9, compass_y - compass_r * 1.3, compass_x - compass_r * 0.9, compass_y - compass_r * 1.08);

	//右侧显示屏外框
	setfillcolor(WHITE);
	ege_fillrect(compass_x + compass_r * 0.75, compass_y - compass_r * 1.3, compass_r * 0.45, compass_r * 0.22);
}

void draw_sidesscreen_GPS(int compass_x, int compass_y, int compass_r) {
	//左侧显示屏外框
	setcolor(EGEARGB(0xff, 0x24, 0x28, 0x33));
	ege_rectangle(compass_x - compass_r * 1.2, compass_y - compass_r * 1.3, compass_r * 0.45, compass_r * 0.22);
	ege_line(compass_x - compass_r * 1.05, compass_y - compass_r * 1.3, compass_x - compass_r * 1.05, compass_y - compass_r * 1.08);
	ege_line(compass_x - compass_r * 0.9, compass_y - compass_r * 1.3, compass_x - compass_r * 0.9, compass_y - compass_r * 1.08);

	setcolor(EGEARGB(0xff, 0x24, 0x28, 0x33));
	ege_rectangle(compass_x + compass_r * 0.75, compass_y - compass_r * 1.3, compass_r * 0.45, compass_r * 0.22);
}

//画出表盘顶部的三角形
void draw_toptriangle(int compass_x, int compass_y, int compass_r) {
	setfillcolor(WHITE);
	ege_point triangle[3];
	triangle[0].x = compass_x;
	triangle[0].y = compass_y - compass_r;

	triangle[1].x = compass_x - compass_r * 0.07;
	triangle[1].y = compass_y - compass_r * 1.4;

	triangle[2].x = compass_x + compass_r * 0.07;
	triangle[2].y = compass_y - compass_r * 1.4;

	ege_fillpoly(3, triangle);
}

//画出表盘的指针
void draw_points(int compass_x, int compass_y, int compass_r) {
	static int n = 0;
	static int m = 1;
	/*if (GetAsyncKeyState('M') & 0x8000) { // 检测 N 键是否被按下
		if (m == 1 && n < compass_r * 0.6)
			n++;
		else if (m == 1 && n >= compass_r * 0.6) {
			n--;
			m = m * -1;
		}
		else if (m == -1 && n > -compass_r * 0.6)
			n--;
		else if (m == -1 && n <= -compass_r * 0.6) {
			n++;
			m = m * -1;
		}
	}*/
	//三段指针
	setlinewidth(compass_r * 0.015);
	setcolor(WHITE);
	ege_line((compass_r * 0.95) * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_x, (-compass_r * 0.95) * cos((pointrotationangle + realrotationangle) * PI / 180) + compass_y, (compass_r * 0.55) * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_x, (-compass_r * 0.55) * cos((pointrotationangle + realrotationangle) * PI / 180) + compass_y);
	ege_line((compass_r * 0.5) * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_x + n * cos((pointrotationangle + realrotationangle) * PI / 180), (-compass_r * 0.5) * cos((pointrotationangle + realrotationangle) * PI / 180) + compass_y + n * sin((realrotationangle + pointrotationangle) * PI / 180), (-compass_r * 0.5) * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_x + n * cos((pointrotationangle + realrotationangle) * PI / 180), (compass_r * 0.5) * cos((pointrotationangle + realrotationangle) * PI / 180) + compass_y + n * sin((pointrotationangle + realrotationangle) * PI / 180));
	ege_line((-compass_r * 0.95) * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_x, (compass_r * 0.95) * cos((pointrotationangle + realrotationangle) * PI / 180) + compass_y, (-compass_r * 0.55) * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_x, (compass_r * 0.55) * cos((pointrotationangle + realrotationangle) * PI / 180) + compass_y);

	setlinewidth(compass_r * 0.02);
	ege_point triangle1[4];
	triangle1[2].x = 0.12 * compass_r * cos((pointrotationangle + realrotationangle) * PI / 180) - (-0.3 * compass_r) * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_x + n * cos((pointrotationangle + realrotationangle) * PI / 180);
	triangle1[2].y = (-0.3 * compass_r) * cos((pointrotationangle + realrotationangle) * PI / 180) + 0.12 * compass_r * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_y + n * sin((pointrotationangle + realrotationangle) * PI / 180);

	triangle1[0].x = 0.45 * compass_r * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_x + n * cos((pointrotationangle + realrotationangle) * PI / 180);
	triangle1[0].y = (-compass_r * 0.45) * cos((pointrotationangle + realrotationangle) * PI / 180) + compass_y + n * sin((pointrotationangle + realrotationangle) * PI / 180);

	triangle1[1].x = (-0.12 * compass_r) * cos((pointrotationangle + realrotationangle) * PI / 180) - (-0.3 * compass_r) * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_x + n * cos((pointrotationangle + realrotationangle) * PI / 180);
	triangle1[1].y = (-0.3 * compass_r) * cos((pointrotationangle + realrotationangle) * PI / 180) - 0.12 * compass_r * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_y + n * sin((pointrotationangle + realrotationangle) * PI / 180);

	triangle1[3].x = 0.45 * compass_r * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_x + n * cos((pointrotationangle + realrotationangle) * PI / 180);
	triangle1[3].y = (-compass_r * 0.45) * cos((pointrotationangle + realrotationangle) * PI / 180) + compass_y + n * sin((pointrotationangle + realrotationangle) * PI / 180);

	ege_drawpoly(4, triangle1);

	setfillcolor(WHITE);
	ege_point triangle2[3];
	triangle2[0].x = 0.12 * compass_r * cos((pointrotationangle + realrotationangle) * PI / 180) - (0.3 * compass_r) * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_x + n * cos((pointrotationangle + realrotationangle) * PI / 180);
	triangle2[0].y = (0.3 * compass_r) * cos((pointrotationangle + realrotationangle) * PI / 180) + 0.12 * compass_r * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_y + n * sin((pointrotationangle + realrotationangle) * PI / 180);

	triangle2[1].x = -0.45 * compass_r * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_x + n * cos((pointrotationangle + realrotationangle) * PI / 180);
	triangle2[1].y = (compass_r * 0.45) * cos((pointrotationangle + realrotationangle) * PI / 180) + compass_y + n * sin((pointrotationangle + realrotationangle) * PI / 180);

	triangle2[2].x = (-0.12 * compass_r) * cos((pointrotationangle + realrotationangle) * PI / 180) - (0.3 * compass_r) * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_x + n * cos((pointrotationangle + realrotationangle) * PI / 180);
	triangle2[2].y = (0.3 * compass_r) * cos((pointrotationangle + realrotationangle) * PI / 180) - 0.12 * compass_r * sin((pointrotationangle + realrotationangle) * PI / 180) + compass_y + n * sin((pointrotationangle + realrotationangle) * PI / 180);
	ege_fillpoly(3, triangle2);
}

//画表盘外框
void draw_compassOuterframe(int compass_x, int compass_y, int compass_r) {
	setlinewidth(3);
	setfillcolor(EGEARGB(0xff, 0x24, 0x28, 0x33));
	ege_point outerframe_1[6];
	outerframe_1[0].x = compass_x - compass_r * 1.5;
	outerframe_1[0].y = compass_y + compass_r * 1.5;

	outerframe_1[1].x = compass_x - compass_r * 1.5;
	outerframe_1[1].y = compass_y - compass_r * 1.4;

	outerframe_1[2].x = compass_x - compass_r * 1.4;
	outerframe_1[2].y = compass_y - compass_r * 1.5;

	outerframe_1[3].x = compass_x + compass_r * 1.4;
	outerframe_1[3].y = compass_y - compass_r * 1.5;

	outerframe_1[4].x = compass_x + compass_r * 1.5;
	outerframe_1[4].y = compass_y - compass_r * 1.4;

	outerframe_1[5].x = compass_x + compass_r * 1.5;
	outerframe_1[5].y = compass_y + compass_r * 1.5;

	ege_fillpoly(6, outerframe_1);

	setfillcolor(BLACK);
	ege_point outerframe_2[8];
	outerframe_2[0].x = compass_x - compass_r * 1.4 + 1;
	outerframe_2[0].y = compass_y - compass_r * 1.5 - 1;

	outerframe_2[1].x = compass_x + compass_r * 1.4 + 1;
	outerframe_2[1].y = compass_y - compass_r * 1.5 - 1;

	outerframe_2[2].x = compass_x + compass_r * 1.5 + 1;
	outerframe_2[2].y = compass_y - compass_r * 1.4 - 1;

	outerframe_2[3].x = compass_x + compass_r * 1.5 + 1;
	outerframe_2[3].y = compass_y + compass_r * 1.5 - 1;

	outerframe_2[4].x = compass_x + compass_r * 1.52 + 1;
	outerframe_2[4].y = compass_y + compass_r * 1.42 - 1;

	outerframe_2[5].x = compass_x + compass_r * 1.52 + 1;
	outerframe_2[5].y = compass_y - compass_r * 1.42 - 1;

	outerframe_2[6].x = compass_x + compass_r * 1.42 + 1;
	outerframe_2[6].y = compass_y - compass_r * 1.52 - 1;

	outerframe_2[7].x = compass_x - compass_r * 1.32 + 1;
	outerframe_2[7].y = compass_y - compass_r * 1.52 - 1;

	ege_fillpoly(8, outerframe_2);

	setlinewidth(3);
	setcolor(EGEARGB(0xff, 0x1b, 0x20, 0x25));
	ege_point outerframe_3[19];
	outerframe_3[0].x = compass_x - compass_r * 1.4;
	outerframe_3[0].y = compass_y + compass_r * 0.9;

	outerframe_3[1].x = compass_x;
	outerframe_3[1].y = compass_y + compass_r * 1.5;

	outerframe_3[2].x = compass_x;
	outerframe_3[2].y = compass_y + compass_r * 1.5;

	outerframe_3[3].x = compass_x + compass_r * 1.4;
	outerframe_3[3].y = compass_y + compass_r * 0.9;

	outerframe_3[4].x = compass_x + compass_r * 1.4;
	outerframe_3[4].y = compass_y + compass_r * 0.1;

	outerframe_3[5].x = compass_x + compass_r * 1.4;
	outerframe_3[5].y = compass_y - compass_r * 0.1;

	outerframe_3[6].x = compass_x + compass_r * 1.4;
	outerframe_3[6].y = compass_y - compass_r * 1.2;

	outerframe_3[7].x = compass_x + compass_r * 1.3;
	outerframe_3[7].y = compass_y - compass_r * 1.3;

	outerframe_3[8].x = compass_x + compass_r * 1.3;
	outerframe_3[8].y = compass_y - compass_r * 1.3;

	outerframe_3[9].x = compass_x + compass_r * 1.2;
	outerframe_3[9].y = compass_y - compass_r * 1.4;

	outerframe_3[10].x = compass_x;
	outerframe_3[10].y = compass_y - compass_r * 1.4;

	outerframe_3[11].x = compass_x;
	outerframe_3[11].y = compass_y - compass_r * 1.4;

	outerframe_3[12].x = compass_x - compass_r * 1.2;
	outerframe_3[12].y = compass_y - compass_r * 1.4;

	outerframe_3[13].x = compass_x - compass_r * 1.3;
	outerframe_3[13].y = compass_y - compass_r * 1.3;

	outerframe_3[14].x = compass_x - compass_r * 1.3;
	outerframe_3[14].y = compass_y - compass_r * 1.3;

	outerframe_3[15].x = compass_x - compass_r * 1.4;
	outerframe_3[15].y = compass_y - compass_r * 1.2;

	outerframe_3[16].x = compass_x - compass_r * 1.4;
	outerframe_3[16].y = compass_y - compass_r * 0.1;

	outerframe_3[17].x = compass_x - compass_r * 1.4;
	outerframe_3[17].y = compass_y - compass_r * 0.1;

	outerframe_3[18].x = compass_x - compass_r * 1.4;
	outerframe_3[18].y = compass_y + compass_r * 0.9 + 1;
	ege_bezier(19, outerframe_3);
	setfillcolor(EGEARGB(0xff, 0x1b, 0x20, 0x25));
	floodfill(compass_x, compass_y, EGEARGB(0xff, 0x1b, 0x20, 0x25));



}

//画出表盘第二部分中的五个小圆（实际五个小圆是五个刻度）
void draw_compassCricle(int compass_x, int compass_y, int compass_r) {
	setfillcolor(WHITE);
	ege_fillellipse(compass_x - compass_r * 0.025, compass_y - compass_r * 0.025, compass_r * 0.05, compass_r * 0.05);
	ege_fillellipse(compass_x + compass_r * 0.3 * cos(-(pointrotationangle + realrotationangle) * PI / 180) - compass_r * 0.025, compass_y - compass_r * 0.025 - compass_r * 0.3 * sin(-(pointrotationangle + realrotationangle) * PI / 180), compass_r * 0.05, compass_r * 0.05);
	ege_fillellipse(compass_x - compass_r * 0.3 * cos(-(pointrotationangle + realrotationangle) * PI / 180) - compass_r * 0.025, compass_y - compass_r * 0.025 + compass_r * 0.3 * sin(-(pointrotationangle + realrotationangle) * PI / 180), compass_r * 0.05, compass_r * 0.05);
	ege_fillellipse(compass_x + compass_r * 0.6 * cos(-(pointrotationangle + realrotationangle) * PI / 180) - compass_r * 0.025, compass_y - compass_r * 0.025 - compass_r * 0.6 * sin(-(pointrotationangle + realrotationangle) * PI / 180), compass_r * 0.05, compass_r * 0.05);
	ege_fillellipse(compass_x - compass_r * 0.6 * cos(-(pointrotationangle + realrotationangle) * PI / 180) - compass_r * 0.025, compass_y - compass_r * 0.025 + compass_r * 0.6 * sin(-(pointrotationangle + realrotationangle) * PI / 180), compass_r * 0.05, compass_r * 0.05);
}

//画出中心的飞机图案
void draw_compassPlane(int compass_x, int compass_y, int compass_r) {
	setcolor(WHITE);
	setlinewidth(compass_r * 0.015);
	const int planepoints[38] = { compass_x, compass_y - 0.25 * compass_r, compass_x - compass_r * 0.025, compass_y - compass_r * 0.2, compass_x - compass_r * 0.025, compass_y - compass_r * 0.065, compass_x - compass_r * 0.22, compass_y + compass_r * 0.02, compass_x - compass_r * 0.225, compass_y + compass_r * 0.055, compass_x - compass_r * 0.025, compass_y + compass_r * 0.025, compass_x - compass_r * 0.025, compass_y + compass_r * 0.15, compass_x - compass_r * 0.11, compass_y + compass_r * 0.23, compass_x - compass_r * 0.015, compass_y + compass_r * 0.19, compass_x, compass_y + compass_r * 0.22, compass_x + compass_r * 0.015, compass_y + compass_r * 0.19, compass_x + compass_r * 0.11, compass_y + compass_r * 0.23, compass_x + compass_r * 0.025, compass_y + compass_r * 0.15, compass_x + compass_r * 0.025, compass_y + compass_r * 0.025, compass_x + compass_r * 0.225, compass_y + compass_r * 0.055, compass_x + compass_r * 0.22, compass_y + compass_r * 0.02, compass_x + compass_r * 0.025, compass_y - compass_r * 0.065, compass_x + compass_r * 0.025, compass_y - compass_r * 0.2, compass_x, compass_y - 0.25 * compass_r };
	drawpoly(19, planepoints);
}

//画出三个表盘之间的分割线
void draw_compassLine(int compass_x, int compass_y, int compass_r) {
	//设置线条颜色和粗细
	setcolor(BLACK);
	setlinewidth(compass_r * 0.015);

	//绘制表盘中三个部分的分割线
	ege_line((-compass_r * 0.85 * 0.78 * cos(-(pointrotationangle + realrotationangle) * PI / 180)) + (-compass_r * 0.25 * sin(-(pointrotationangle + realrotationangle) * PI / 180)) + compass_x, (-compass_r * 0.25 * cos(-(pointrotationangle + realrotationangle) * PI / 180)) - (-compass_r * 0.85 * 0.78 * sin(-(pointrotationangle + realrotationangle) * PI / 180)) + compass_y, (compass_r * 0.85 * 0.78 * cos(-(pointrotationangle + realrotationangle) * PI / 180)) - (compass_r * 0.25 * sin(-(pointrotationangle + realrotationangle) * PI / 180)) + compass_x, (-compass_r * 0.25 * cos(-(pointrotationangle + realrotationangle) * PI / 180)) + (-compass_r * 0.85 * 0.78 * sin(-(pointrotationangle + realrotationangle) * PI / 180)) + compass_y);
	ege_line((-compass_r * 0.85 * 0.78 * cos(-(pointrotationangle + realrotationangle) * PI / 180)) + (compass_r * 0.25 * sin(-(pointrotationangle + realrotationangle) * PI / 180)) + compass_x, (compass_r * 0.25 * cos(-(pointrotationangle + realrotationangle) * PI / 180)) - (-compass_r * 0.85 * 0.78 * sin(-(pointrotationangle + realrotationangle) * PI / 180)) + compass_y, (compass_r * 0.85 * 0.78 * cos(-(pointrotationangle + realrotationangle) * PI / 180)) + (compass_r * 0.25 * sin(-(pointrotationangle + realrotationangle) * PI / 180)) + compass_x, (compass_r * 0.25 * cos(-(pointrotationangle + realrotationangle) * PI / 180)) - (compass_r * 0.85 * 0.78 * sin(-(pointrotationangle + realrotationangle) * PI / 180)) + compass_y);
}

//画出表盘内框的线条
void draw_compassFrameLine(int compass_x, int compass_y, int compass_r) {
	//设置线条颜色和粗细
	setcolor(BLACK);
	setlinewidth(compass_r * 0.015);

	//绘制表盘内框内外线条
	ege_ellipse(compass_x - compass_r, compass_y - compass_r, 2 * compass_r, 2 * compass_r);
	ege_ellipse(compass_x - 0.78 * compass_r, compass_y - 0.78 * compass_r, 1.56 * compass_r, 1.56 * compass_r);
}

//画出表盘右侧的文字
void draw_rightTexts(int compass_x, int compass_y, int compass_r) {
	//设置文本背景填充色
	setfillcolor(EGEARGB(0xff, 0x4e, 0x58, 0x26));
	settextjustify(CENTER_TEXT, CENTER_TEXT);
	//绘制文本内容
	ege_fillrect(compass_x + compass_r * 1.1, compass_y - compass_r * 0.55, compass_r * 0.15, compass_r * 1.1);
	setbkmode(1);
	setfont(compass_r * 0.15, compass_r * 0.07, "黑体", 0, 0, 20, 0, 0, 0);
	setcolor(WHITE);
	ege_drawtext("V", compass_x + compass_r * 1.185, compass_y - compass_r * 0.45);
	setbkmode(1);
	setfont(compass_r * 0.15, compass_r * 0.07, "黑体", 0, 0, 20, 0, 0, 0);
	setcolor(WHITE);
	ege_drawtext("O", compass_x + compass_r * 1.185, compass_y - compass_r * 0.3);
	setbkmode(1);
	setfont(compass_r * 0.15, compass_r * 0.07, "黑体", 0, 0, 20, 0, 0, 0);
	setcolor(WHITE);
	ege_drawtext("R", compass_x + compass_r * 1.185, compass_y - compass_r * 0.15);
	setbkmode(1);
	setfont(compass_r * 0.15, compass_r * 0.07, "黑体", 0, 0, 20, 0, 0, 0);
	setcolor(WHITE);
	ege_drawtext("L", compass_x + compass_r * 1.185, compass_y + compass_r * 0.15);
	setbkmode(1);
	setfont(compass_r * 0.15, compass_r * 0.07, "黑体", 0, 0, 20, 0, 0, 0);
	setcolor(WHITE);
	ege_drawtext("O", compass_x + compass_r * 1.185, compass_y + compass_r * 0.3);
	setbkmode(1);
	setfont(compass_r * 0.15, compass_r * 0.07, "黑体", 0, 0, 20, 0, 0, 0);
	setcolor(WHITE);
	ege_drawtext("C", compass_x + compass_r * 1.185, compass_y + compass_r * 0.45);
}

//画出表盘左侧的文字
void draw_leftTexts(int compass_x, int compass_y, int compass_r) {
	//绘制文本内容
	setbkmode(1);
	setfont(compass_r * 0.15, 0, "黑体", 0, 0, 20, 0, 0, 0);
	setcolor(WHITE);
	ege_drawtext("G", compass_x - compass_r * 1.13, compass_y - compass_r * 0.08);
	setbkmode(1);
	setfont(compass_r * 0.15, 0, "黑体", 0, 0, 20, 0, 0, 0);
	setcolor(WHITE);
	ege_drawtext("S", compass_x - compass_r * 1.13, compass_y + compass_r * 0.08);
	setcolor(WHITE);
	setlinewidth(compass_r * 0.01);
	ege_line(compass_x - compass_r * 1.08, compass_y, compass_x - compass_r * 1.02, compass_y);
}

//画出表盘内文字
void draw_innerTexts(double realrotationangle, int compass_x, int compass_y, int compass_r) {
	for (int i = 0; i < 360; i += 30) {
		double textAngle = realrotationangle + i;
		double rad = textAngle * PI / 180.0;
		double textPosX = compass_x + 0.85 * compass_r * sin(rad);
		double textPosY = compass_y - 0.85 * compass_r * cos(rad);

		LOGFONTW font;
		setfont(compass_r * 0.2, 0, "Leelawadee");
		settextjustify(CENTER_TEXT, CENTER_TEXT);
		getfont(&font);
		font.lfEscapement = -textAngle * 10;
		font.lfWeight = 550;
		setfont(&font);
#if 0
		xyprintf(compass_x + 0.8 * compass_r * cos(rad), compass_y - 0.8 * compass_r * sin(rad), "%d", i);
#endif
		char strBuffer[64];
		sprintf_s(strBuffer, "%d", i / 10);
		ege_drawtext(strBuffer, textPosX, textPosY);
	}
}

//画出刻度
void draw_scale(int compass_x, int compass_y, int compass_r) {
	for (double i = -realrotationangle; i < 360.0 - realrotationangle; i += 5.0)
	{
		//设置线条颜色和粗细
		setlinewidth(compass_r * 0.01);
		setcolor(WHITE);
		//绘制刻度线
		ege_line(compass_x + compass_r * cos(PI * i / 180), compass_y - compass_r * sin(PI * i / 180), compass_x + compass_r * 0.93 * cos(PI * i / 180), compass_y - compass_r * 0.93 * sin(PI * i / 180));
	}
}

//刷新界面，制造旋转效果
void refresh(int compass_x, int compass_y, int compass_r) {
	//compass_angle_original_data = 270;
	realrotationangle = 360 - rotationangle;
	pointrotationangle = compass_angle_original_data + datarotationangle;
	//data的处理
	compass_temp_data = compass_angle_original_data;
	while (compass_temp_data < 0) {
		compass_temp_data += 360;
	}
	while (compass_temp_data > 360) {
		compass_temp_data -= 360;
	}
	//画表的外框
	draw_compassOuterframe(compass_x, compass_y, compass_r);

	//绘图
	draw1(compass_x, compass_y, compass_r);
	draw10(compass_x, compass_y, compass_r);
	draw100(compass_x, compass_y, compass_r);

	//遮盖
	cover(compass_x, compass_y, compass_r);

	//画表两边的两个数字显示屏
	draw_sidesscreen(compass_x, compass_y, compass_r);

	//表右侧的文字
	draw_rightTexts(compass_x, compass_y, compass_r);

	//画表盘上方一个三角形
	draw_toptriangle(compass_x, compass_y, compass_r);

	//画内表盘的刻度
	draw_scale(compass_x, compass_y, compass_r);

	//画内表盘第二部分上的五个白色的小圆
	draw_compassCricle(compass_x, compass_y, compass_r);

	//画内表盘中心的飞机图标
	draw_compassPlane(compass_x, compass_y, compass_r);

	//画内表盘三个部分之间的分割线
	draw_compassLine(compass_x, compass_y, compass_r);

	//画内表盘内框的线条
	draw_compassFrameLine(compass_x, compass_y, compass_r);

	//画指针
	draw_points(compass_x, compass_y, compass_r);

	//表左侧的文字
	draw_leftTexts(compass_x, compass_y, compass_r);

	//画内表盘的文字
	draw_innerTexts(realrotationangle, compass_x, compass_y, compass_r);

	//画表盘下方的两个旋钮
	draw_downbotten(realrotationangle, compass_x, compass_y, compass_r);
}

//绘制光效
void draw_light(int compass_x, int compass_y, int compass_r) {

	ege_point outerframe_3[19];
	outerframe_3[0].x = compass_x - compass_r * 1.4;
	outerframe_3[0].y = compass_y + compass_r * 0.9;

	outerframe_3[1].x = compass_x - 0.25 * compass_r;
	outerframe_3[1].y = compass_y + compass_r * 1.32;

	outerframe_3[2].x = compass_x + 0.25 * compass_r;
	outerframe_3[2].y = compass_y + compass_r * 1.32;

	outerframe_3[3].x = compass_x + compass_r * 1.4;
	outerframe_3[3].y = compass_y + compass_r * 0.9;

	outerframe_3[4].x = compass_x + compass_r * 1.4;
	outerframe_3[4].y = compass_y + compass_r * 0.1;

	outerframe_3[5].x = compass_x + compass_r * 1.4;
	outerframe_3[5].y = compass_y - compass_r * 0.1;

	outerframe_3[6].x = compass_x + compass_r * 1.4;
	outerframe_3[6].y = compass_y - compass_r * 1.2;

	outerframe_3[7].x = compass_x + compass_r * 1.3;
	outerframe_3[7].y = compass_y - compass_r * 1.3;

	outerframe_3[8].x = compass_x + compass_r * 1.3;
	outerframe_3[8].y = compass_y - compass_r * 1.3;

	outerframe_3[9].x = compass_x + compass_r * 1.2;
	outerframe_3[9].y = compass_y - compass_r * 1.4;

	outerframe_3[10].x = compass_x;
	outerframe_3[10].y = compass_y - compass_r * 1.4;

	outerframe_3[11].x = compass_x;
	outerframe_3[11].y = compass_y - compass_r * 1.4;

	outerframe_3[12].x = compass_x - compass_r * 1.2;
	outerframe_3[12].y = compass_y - compass_r * 1.4;

	outerframe_3[13].x = compass_x - compass_r * 1.3;
	outerframe_3[13].y = compass_y - compass_r * 1.3;

	outerframe_3[14].x = compass_x - compass_r * 1.3;
	outerframe_3[14].y = compass_y - compass_r * 1.3;

	outerframe_3[15].x = compass_x - compass_r * 1.4;
	outerframe_3[15].y = compass_y - compass_r * 1.2;

	outerframe_3[16].x = compass_x - compass_r * 1.4;
	outerframe_3[16].y = compass_y - compass_r * 0.1;

	outerframe_3[17].x = compass_x - compass_r * 1.4;
	outerframe_3[17].y = compass_y - compass_r * 0.1;

	outerframe_3[18].x = compass_x - compass_r * 1.4;
	outerframe_3[18].y = compass_y + compass_r * 0.9 + 1;

	ege_point compass_points{ compass_x, compass_y };
	ege_setpattern_ellipsegradient(compass_points, EGEARGB(0x00, 0xff, 0x9b, 0x4b), compass_x - 3 * compass_r, compass_y - 3 * compass_r, 6 * compass_r, 6 * compass_r, EGEARGB(G_light / 7, 0xff, 0x60, 0x36));
	ege_fillpoly(19, outerframe_3);
}

void draw_compass(int compass_x, int compass_y, int compass_r)
{
	refresh(compass_x, compass_y, compass_r * 1 / 3);
	//	draw_screw(compass_x * 0.25, compass_y * 0.15, compass_r * 1 / 3 * 0.05, 45);
	//	draw_screw(compass_x * 1.77, compass_y * 0.15, compass_r * 1 / 3 * 0.05, 45);
	//	draw_screw(compass_x * 1.79, compass_y * 1.85, compass_r * 1 / 3 * 0.05, 45);
	draw_light(compass_x, compass_y, compass_r * 1 / 3);
}
